package com.easytake.emotioncat.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.easytake.emotioncat.entity.EmFoodEntity;
import com.easytake.emotioncat.entity.EmUserInfoEntity;
import com.easytake.emotioncat.mapper.EmFoodMapper;
import com.easytake.emotioncat.service.IEmFoodService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 猫粮表 服务实现类
 * </p>
 *
 * @author baomidou
 * @since 2022-11-11
 */
@Service
public class EmFoodServiceImpl extends ServiceImpl<EmFoodMapper, EmFoodEntity> implements IEmFoodService {

    @Override
    public EmFoodEntity queryByUserIdAndCategory(String userId, String category) {
        QueryWrapper<EmFoodEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EmFoodEntity::getUserId, userId).eq(EmFoodEntity::getCategory, category);
        List<EmFoodEntity> foodEntityList = this.list(queryWrapper);
        if (foodEntityList.size() > 0) {
            return foodEntityList.get(0);
        }
        return null;
    }

    @Override
    public List<EmFoodEntity> queryByUserId(String userId) {
        QueryWrapper<EmFoodEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EmFoodEntity::getUserId, userId);
        List<EmFoodEntity> foodEntityList = this.list(queryWrapper);
        return foodEntityList;
    }
}
